package com.example.zsr.downloadcontinue.entity;

/**
 * Created by zhengshaorui on 2017/2/27.
 */

public class DownloadConfigGuration {

    private static int THREAD_COUNT_MAX = 10;//最大线程数为10
    private String filename;
    private String fileurl;
    private int threadcount;
    private int priority;



    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public String getFileurl() {
        return fileurl;
    }

    public void setFileurl(String fileurl) {
        this.fileurl = fileurl;
    }

    public int getThreadcount() {
        return threadcount;
    }

    public void setThreadcount(int threadcount) {
        if (threadcount >= THREAD_COUNT_MAX){
            threadcount = THREAD_COUNT_MAX;
        }
        this.threadcount = threadcount;
    }

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    /**
     *
     * @param filename  文件名
     * @param fileurl   文件rul
     * @param threadcount 分配的线程数
     * @param priority   优先级
     */

    public DownloadConfigGuration(String fileurl,String filename,
                                   int threadcount, int priority) {


        this.fileurl = fileurl;
        this.filename = filename;
        this.threadcount = threadcount;
        this.priority = priority;
    }

    @Override
    public String toString() {
        return "DownloadConfigGuration{" +
                ", filename='" + filename + '\'' +
                ", fileurl='" + fileurl + '\'' +
                ", threadcount=" + threadcount +
                ", priority=" + priority +
                '}';
    }


    public static class Builder{
        private String filename;
        private String fileurl;
        private int threadcount;
        private int priority;

        public Builder(){}

        public Builder setUrl(String url){
            this.fileurl = url;
            return this;
        }
        public Builder setName(String name){
            this.filename = name;
            return this;
        }
        public Builder setThreadCount(int threadcount){
            this.threadcount = threadcount;
            return this;
        }
        public Builder setPriority(int priority){
            this.priority = priority;
            return this;
        }

        public DownloadConfigGuration build(){
            return new DownloadConfigGuration(fileurl,filename,threadcount,priority);
        }
    }
}


